package com.awesumgames.testgame;

import java.util.ArrayList;

import tv.ouya.console.api.OuyaController;

import com.awesumgames.awesum.AwesumGlobal.Awesum.*;
import com.awesumgames.awesum.controls.Control.Ouya;
import com.awesumgames.awesum.Drawable;
import com.awesumgames.awesum.Quaternion;
import com.awesumgames.awesum.Vector3;
import com.bulletphysics.collision.shapes.TriangleIndexVertexArray;

public class ParametricThing extends Drawable {

	public ParametricThing() {
		super();
	}
	
	private class Vertex {
		public Vector3 v = new Vector3();
		public boolean shared = true;
		public Vector3 n = new Vector3();
		public BufferSet vertices(ArrayList<Vertex> vs) {
			BufferSet bs = new BufferSet();
			for (Vertex vertex : vs) {
				bs.add(vertex.v, vertex.n, vertex.shared);
			}
			return bs;
		}
		public byte[] indices() {
			return new byte[4];
		}
	}
	private class BufferSet {
		public ArrayList<Float> vertices = new ArrayList<Float>();
		public ArrayList<Float> normals = new ArrayList<Float>();
		public ArrayList<Byte> indices = new ArrayList<Byte>();
		public TriangleIndexVertexArray physMesh = null;
		public void add(Vector3 v, Vector3 c, boolean shared) {
			if (shared) { //see if point is already in list
				
				
			}
			vertices.add(v.x);
			vertices.add(v.y);
			vertices.add(v.z);
			normals.add(c.x);
			normals.add(c.y);
			normals.add(c.z);
			
		}
		public void assemble() {
			
			
			//int numTriangles, ByteBuffer triangleIndexBase, int triangleIndexStride, int numVertices, ByteBuffer vertexBase, int vertexStride) 
			physMesh = new TriangleIndexVertexArray();//
		}
	}
	
	public void load() {
		super.load(TraitFlag.Gl.flag | TraitFlag.Move.flag);
		
		float r[] = null, g[] = null, b[] = null, a[] = null;
		Vector3 scale = new Vector3(1f, 1f, 1f);
		
		/*r = new float[]{1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f};
		g = new float[]{0f, .25f, .5f, .5f, .5f, .75f, .5f, .75f};
		b = new float[]{0f, .25f, .5f, .5f, .5f, .75f, .5f, .75f};
		a = new float[]{1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f};
		float vertices[] = new float[] {
			0f, 0f, 0f,		r[0], g[0], b[0], a[0],
			1f, 0f, 0f,		r[1], g[1], b[1], a[1],
			1f, 0f, 1f,		r[2], g[2], b[2], a[2],
			0f, 0f, 1f,		r[3], g[3], b[3], a[3]//,
			//0f, 0f, 1f,		r[4], g[4], b[4], a[4],
			//1f, 0f, 1f,		r[5], g[5], b[5], a[5],
			//1f, 1f, 1f,		r[6], g[6], b[6], a[6],
			//0f, 1f, 1f,		r[7], g[7], b[7], a[7]
		};
		byte indices[] = new byte[] {
			0, 1, 2,	2, 3, 0
		};*/
		
		BufferSet bs = new BufferSet();
		
		
		
		//gl.setVertices(vertices);
		//gl.setIndices(indices);
		gl.setDrawModeTriangles();
		gl.translate.set(-.5f, -.5f, -.5f);
		move.drawRotation = true;
		
		reset();
	}
	
	private void reset() {
	}
	
	public void step() {
		super.step();
		
		move.rot.multiply(new Quaternion().setAxisAngleDeg(Axis.Y, 1f));
		
		if (Ouya.justPressed(0, OuyaController.BUTTON_O))
			reset();
		/*float axisX = Math.min(c.getAxisValue(OuyaController.AXIS_LS_X), 1f);
        float axisY = Math.min(c.getAxisValue(OuyaController.AXIS_LS_Y), 1f);
        float stickMag = (float)Math.sqrt(axisX * axisX + axisY * axisY);
        if (stickMag >= OuyaController.STICK_DEADZONE) {
            // normalize the direction vec
            //shootDir.x = axisX / stickMag;
        	move.rot.rotateLocYDeg(-2f * axisX);
        	//origin.x += .35 * (axisX);// / (stickMag - OuyaController.STICK_DEADZONE));
            //shootDir.y = axisY / stickMag;
        }*/
	}
}
